package com.wen.pay.service.impl;

import com.wechat.pay.java.service.payments.nativepay.NativePayService;
import com.wechat.pay.java.service.payments.nativepay.model.Amount;
import com.wechat.pay.java.service.payments.nativepay.model.PrepayRequest;
import com.wechat.pay.java.service.payments.nativepay.model.PrepayResponse;
import com.wen.pay.config.WxPayConfig;
import com.wen.pay.service.WxPayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

@Slf4j
@Service
public class WxPayServiceImpl implements WxPayService {
    @Resource
    private NativePayService nativePayService;
    @Resource
    private WxPayConfig wxPayConfig;
    @Override
    public Map<String, Object> nativePay(Long productId) {
        log.info("生成订单");
        //TODO 数据库创建订单

        //调用统一下单API
        PrepayRequest request = new PrepayRequest();
        Amount amount = new Amount();
        amount.setTotal(100);
        request.setAmount(amount);
        request.setAppid(wxPayConfig.getAppid());
        request.setMchid(wxPayConfig.getMchId());
        request.setDescription("测试商品标题");
        request.setNotifyUrl(wxPayConfig.getDomain()+wxPayConfig.getNotifyDomain());
        request.setOutTradeNo("100861102");
        PrepayResponse response = nativePayService.prepay(request);
        log.info("调用-微信下单接口,响应结果：{}",response);
        return null;
    }
}
